package com.jltx.xq.relaxnewspro.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.jltx.xq.relaxnewspro.R;
import com.jltx.xq.relaxnewspro.adapter.PagerAdapter;
import com.jltx.xq.relaxnewspro.api.NewsApi;

/**
 * Created by bo on 2017/5/1.
 */

public class BaseNewsFragment extends AbsTopNavigationFragment {
    private PagerAdapter pagerAdapter;
    private String[] name;
    private String[] url;

    @Override
    protected PagerAdapter initPagerAdapter() {
        name = NewsApi.getNewsTitle();
        url = NewsApi.getNewsUrl();
        pagerAdapter = new PagerAdapter(getChildFragmentManager(),name) {
            @Override
            public Fragment getItem(int position) {
                NewsFragment fragment = new NewsFragment();
                Bundle bundle = new Bundle();
                bundle.putString(getString(R.string.id_url),url[position]);
                bundle.putString(getString(R.string.id_category),name[position]);
                fragment.setArguments(bundle);
                return fragment;
            }
        };
        return pagerAdapter;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if(getChildFragmentManager().getFragments()!=null){
            getChildFragmentManager().getFragments().clear();
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }
}
